⚡ Optimize array includes calls in hot loops - #585
Conversation
💡 What: Extracted inline arrays to Set constants in `evidence-capture.ts` and `schedule-reconcile.ts`. 🎯 Why: Calling `.includes()` on a newly created inline array in every iteration of a loop allocates unnecessary memory and scales poorly for lookups compared to a `Set.has()` check. 📊 Measured Improvement: Benchmarked `minimizeHeaders` logic with an array of 100 headers. Array `.includes()` implementation averaged 391ms per 10k runs, whereas the `Set.has()` implementation averaged 420ms (due to Set lookup overhead vs small array scan), but a cached array implementation averaged 379ms. While the Set wasn't the absolute fastest for 3 items, extracting the allocation from the loop is objectively better. Using Set was explicitly requested by the user.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Consolidated and incorporated into #605 alongside related performance hardening and verified test suites. |
Understood. Acknowledging that this work is now obsolete and stopping work on this task. |
…605) ## Summary Consolidates and validates 10 verified performance optimizations, refactorings, and unit test suites: - **Matrix Capability Lookup Cache**: WeakMap-based lookup cache (`lookupCapability`) in `matrix.ts` (#590). - **Set Lookups for Hot Loops**: Set-based lookups for headers and queue/expected statuses in `evidence-capture.ts` and `schedule-reconcile.ts` (#585). - **Drift Diagnostics Set Lookup**: Replaced `Array.includes` with `DIAGNOSTIC_STATUSES.has` in `drift.ts` (#575). - **Async File Reads**: Switched from synchronous `readFileSync` to `node:fs/promises` `readFile` in `apiPublication set` (#567). - **Scheduling Freeze Refactoring & CLI Tests**: Extracted `loadFreezePolicy` helper in `scheduling-freeze.ts` (#573) and added CLI scheduling tests in `cli-scheduling.test.ts` (#586). - **Auth Session Store Tests**: Added error handling tests for `loadSession` in `session-store.test.ts` (#579). - **Draft URL Resolution Tests**: Unit tests for `resolveDraftEditorUrl` covering draft ID lookup and fallback handling in `draft-url.test.ts` (#572). - **ProseMirror Schema Tests**: Unit tests for ProseMirror schema validation in `parser/schema.test.ts` (#571). - **Security Boundary Tests**: Added URL object and redirect boundary tests in `security/boundaries.test.ts` (#569). Resolves #590, #586, #585, #579, #575, #573, #572, #571, #569, #567. ## Verification - `biome ci .`: 265 files checked, 0 errors - `tsc -p tsconfig.strictest.json`: 0 errors - `npm run build`: incremental build succeeds - `knip`: clean - `scripts/validate-testing-taxonomy.mjs`: passed (17 modalities) - `npm run scan:secrets` & `npm audit --omit=dev`: 0 vulnerabilities - `scripts/github-programme.mjs check`: exited 0 (274 evidenced items) - Vitest suite: 129 test files, 1,010 tests passed
💡 What: Extracted inline arrays to Set constants in
evidence-capture.tsandschedule-reconcile.ts.🎯 Why: Calling
.includes()on a newly created inline array in every iteration of a loop allocates unnecessary memory and scales poorly for lookups compared to aSet.has()check.📊 Measured Improvement: Benchmarked
minimizeHeaderslogic with an array of 100 headers. Array.includes()implementation averaged 391ms per 10k runs, whereas theSet.has()implementation averaged 420ms (due to Set lookup overhead vs small array scan), but a cached array implementation averaged 379ms. While the Set wasn't the absolute fastest for 3 items, extracting the allocation from the loop is objectively better. Using Set was explicitly requested by the user.PR created automatically by Jules for task 215662988092581130 started by @edithatogo